//
//  SWPhotoViewerAssetFetcher.swift
//  ChildStory
//
//  Created by linhan on 2017/1/4.
//  Copyright © 2017年 Aiya. All rights reserved.
//

import Foundation
class SWPhotoViewerAssetFetcher:NSObject,SWPhotoViewerFetcher
{
    weak var delegate:SWPhotoViewerFetcherDelegate?
    
    
    func fetch(photo:SWPVPhoto)
    {
        if let aPhoto = photo.object as? SWALPhoto
        {
            delegate?.fetchStart()
            SWAssetsLibraryHelper.shared().fetchOriginImage(photos: [aPhoto], completeCallback: {[weak self] results in
                if let result = results.valueAt(0),
                    let image = result.image {
                    self?.delegate?.fetchSuccess(image: image)
                } else{
                    let fetchError = NSError(domain: "sw", code: 404, userInfo: nil)
                    self?.delegate?.fetchFailure(error: fetchError)
                }
                
                }, options: nil)
        }
    }
}
